﻿using System;
using System.Data;
using System.Xml;
using System.Collections;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Configuration;

namespace DataAccess.Operate
{
    public class DA_User_Permission_Inherit : SqlInteractionBase
    {
        #region 取某人的权限
        public DataTable getUserPurview(int iLogin)
        {
            string strSQL = "select Permission_Module_Purview from t_User_Permission where Permission_LoginID=@iLogin";
            AppSettingsReader _configReader = new AppSettingsReader();

            SqlDataAdapter dsCommand = new SqlDataAdapter();
            DataSet ds = new DataSet();

            try
            {
                dsCommand.SelectCommand = new SqlCommand();
                dsCommand.SelectCommand.Connection = new SqlConnection(_configReader.GetValue("Main.ConnectionString1", typeof(string)).ToString());

                dsCommand.SelectCommand.CommandText = strSQL;
                dsCommand.SelectCommand.CommandType = CommandType.Text;
                dsCommand.SelectCommand.CommandTimeout = 0;
                dsCommand.SelectCommand.Parameters.Add(new SqlParameter("@iLogin", iLogin));

                if (dsCommand.SelectCommand.Connection.State != ConnectionState.Open)
                    dsCommand.SelectCommand.Connection.Open();

                dsCommand.SelectCommand.ExecuteNonQuery();
                dsCommand.Fill(ds);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (dsCommand != null)
                {
                    if (dsCommand.SelectCommand != null)
                    {
                        if (dsCommand.SelectCommand.Connection != null)
                            dsCommand.SelectCommand.Connection.Dispose();
                        dsCommand.SelectCommand.Dispose();
                    }
                    dsCommand.Dispose();
                    dsCommand = null;
                }
            }

            return ds.Tables[0];
        }
        #endregion

        #region 取有权限的部门
        public DataTable getUserBarch(int iLogin)
        {
            string strSQL = "select Barch_DepartmentID,Barch_Department from t_User_Barch where Barch_LoginID=@iLogin order by Barch_Department";
            AppSettingsReader _configReader = new AppSettingsReader();

            SqlDataAdapter dsCommand = new SqlDataAdapter();
            DataSet ds = new DataSet();

            try
            {
                dsCommand.SelectCommand = new SqlCommand();
                dsCommand.SelectCommand.Connection = new SqlConnection(_configReader.GetValue("Main.ConnectionString1", typeof(string)).ToString());

                dsCommand.SelectCommand.CommandText = strSQL;
                dsCommand.SelectCommand.CommandType = CommandType.Text;
                dsCommand.SelectCommand.CommandTimeout = 0;
                dsCommand.SelectCommand.Parameters.Add(new SqlParameter("@iLogin", iLogin));

                if (dsCommand.SelectCommand.Connection.State != ConnectionState.Open)
                    dsCommand.SelectCommand.Connection.Open();

                dsCommand.SelectCommand.ExecuteNonQuery();
                dsCommand.Fill(ds);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (dsCommand != null)
                {
                    if (dsCommand.SelectCommand != null)
                    {
                        if (dsCommand.SelectCommand.Connection != null)
                            dsCommand.SelectCommand.Connection.Dispose();
                        dsCommand.SelectCommand.Dispose();
                    }
                    dsCommand.Dispose();
                    dsCommand = null;
                }
            }

            return ds.Tables[0];
        }
        #endregion
    }
}
